﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Stee.CAP8.MessageBus.Sagas.Core.Sagas
{

    public abstract class Saga 
    {
        public bool WasMarkedAsComplete { get; set; }
        public virtual void MarkAsComplete() => WasMarkedAsComplete = true;

        public bool HoldsNewSagaDataInstance { get; set; }


        public abstract ISagaData CreateNewSagaData();
        public abstract Type GetSagaDataType();
        public bool IsNew => HoldsNewSagaDataInstance ;


    }

    public class Saga<TSagaData> : Saga where TSagaData : ISagaData, new()
    {
        public Saga() 
        {
            HoldsNewSagaDataInstance = true;
        }

        public TSagaData Data { get; set; }
        public override Type GetSagaDataType()
        {
            return typeof(TSagaData);
        }
        public override ISagaData CreateNewSagaData()
        {
            var newSagaData = new TSagaData 
            {
            };
            Data =  newSagaData;
            HoldsNewSagaDataInstance = false;
            return newSagaData;
        }


    }
}
